#ifndef GAMEENGINE_GRAPHICS_MESHES_TRGL_MESH_SUBGROUP_H
#define GAMEENGINE_GRAPHICS_MESHES_TRGL_MESH_SUBGROUP_H

#include <GameEngine/Graphics/graphics_settings.h>

#include <GameEngine/Graphics/Meshes/surface_mesh.h>
#include <GameEngine/Graphics/Meshes/indexed_mesh_primitives.h>
#include <GameEngine/Graphics/Lighting/material.h>

#include <vector>


#ifdef GAMEENGINE_NAMESPACES
namespace GameEngine {
#endif

class TrglMesh;

//=================================================================================

//! Subgroup of triangles in a triangulated surface mesh
/*!
 *  A subgroup of triangles defines a set of triangles within a group of triangles,
 *  so that all the triangle of the subgroup use the same material.
 *
 *  A subgroup of triangles corresponds to the smallest identifiable unit within the
 *  mesh. Which level of detail the mesh goes to, is a matter of choice: for objects
 *  that are only seen from a distance, this would probably be quite coarse; for objects
 *  with close lookups, more details would typically be required. For instance, when
 *  modelling a sword, one may want either finely detailed jewels on the butt to be
 *  in their own triangle subgroup, or to set the whole butt as one single triangle
 *  subgroup if one wants to model the sword with a low number of polygons.
 */
class _Graphics_decl TrglMeshSubGroup {

public:
	TrglMeshSubGroup();
	TrglMeshSubGroup(const TrglMeshSubGroup& rhs);
	virtual ~TrglMeshSubGroup();
	TrglMeshSubGroup& operator=(const TrglMeshSubGroup& rhs);

	const Material& material() const;
	Material& material();

	const std::vector<IndexedTrgl>& triangles() const;
	std::vector<IndexedTrgl>& triangles();

	bool use_transparency() const;
	bool& use_transparency();
	bool has_transparency() const;

	SurfaceMesh::FaceCount face_count() const;

	void clear();

	bool render_subgroup(const Line3d<float>& ray, const TrglMesh& mesh);

protected:
	//! The triangles present in the mesh
	GAMEENGINE_DLL_CLASS_STD(vector,IndexedTrgl) trgls_;

	//! List of triangle subgroups
	Material material_;

	//! Test if some of the triangles may be rendered with transparency
	bool use_transparency_;
};

//=================================================================================


#ifdef GAMEENGINE_NAMESPACES
} // namespace GameEngine
#endif

#endif
